import { ApiCall } from "tsrpc";
import bag_component from "../../component/bag_component";
import gameCfg from "../../gameCfg";
import player from "../../core/rpg/entity/player";
import { ReqInfo, ResInfo, Res_propItem } from "../../shared/api_client/bag/PtlInfo";
import { ComType } from "../../core/tool/component";


export default async function (call: ApiCall<ReqInfo, ResInfo>) {
    let user = call.req._player as player;
    let com_bag = user.getComponent(ComType.背包) as bag_component;
    let findItem = com_bag.findItem_id(call.req.id,call.req.type);
    if(!findItem){
        call.error('道具不存在');
        return;
    }
    let res:Res_propItem = {
        emoji: findItem.emoji,
        icon: findItem.icon || gameCfg.defaultIcon,
        id: findItem.id,
        name: findItem.name,
        desc: findItem.desc,
        type: findItem.type,
        count: findItem.count,
        atts: []
    }
    call.succ({
        info:res,
    })
}
